package cn.webrx;

import cn.webrx.mapper.BookMapper;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringBootVersion;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

@SpringBootApplication @RestController @MapperScan("cn.webrx.mapper")
public class App {
    @Autowired
    private BookMapper bm;
    public static void main(String[] args) {
        SpringApplication.run(App.class,args);
    }
    @GetMapping("/")
    public Object index(){
        //Set<String> set = new HashSet<String>();
        //set.add("java");
        //return set;
        return bm.queryAll();
        //return String.format("<h1>Hello World SpringBoot [%s]</h1>", SpringBootVersion.getVersion());
    }

    @GetMapping("/del")
    public Map<String,Object> del(int id){
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("code",200);
        map.put("msg","删除成功");
        if(bm.delById(id) == 0){
            map.put("code",400);
            map.put("msg","删除失败");
        }
        return map;
    }
}
